package com.fzl.springblogdemo.controller;

import com.fzl.springblogdemo.pojo.request.AddBlogRequest;
import com.fzl.springblogdemo.pojo.request.UpdateBlogRequest;
import com.fzl.springblogdemo.pojo.response.BlogInfoResponse;
import com.fzl.springblogdemo.service.impl.BlogService;
import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("blog")
@RestController
@Slf4j
public class BlogController {
    //也是注入，注入接口，来实现 实现方法类
    @Resource(name="blogServiceImpl")
    private BlogService blogService;

    @RequestMapping("/getList")
    public List<BlogInfoResponse> getList() {
        log.info("获取列表");
        List<BlogInfoResponse> blogInfos=blogService.getList();
        return blogInfos;
    }

    @RequestMapping("getBlogDetail")
    public BlogInfoResponse getBlogDetail(@NotNull Integer blogId){

        log.info("获取详情:"+blogId);
        return blogService.getBolgDetail(blogId);
    }

    @RequestMapping("/addBlog")
    public Boolean addBlog(@RequestBody @Validated AddBlogRequest addBlogRequest){
        log.info("发布博客：useiId:{},tilte:{}"+addBlogRequest.getUserId()+addBlogRequest.getTitle());
        return blogService.addBlog(addBlogRequest);
    }

    @RequestMapping("/updateBlog")
     public Boolean updateBlog(@RequestBody @Validated UpdateBlogRequest updateBlogRequest){
        log.info("更新博客："+updateBlogRequest);
        return blogService.updateBlog(updateBlogRequest);
     }

    @RequestMapping("/deleteBlog")
    public Boolean deleteBlog(Integer blogId){
        log.info("删除博客："+blogId);
        return blogService.deleteBlog(blogId);
    }
 }

